<?php

class AutoCreateTimeAndUpdateTimeBehavior extends CActiveRecordBehavior
{
	public $createTimeField;
	public $updateTimeField;
	
	public function beforeValidate($event)
	{
		$time = date('Y-m-d H:i:s');
		if($this->getOwner()->hasAttribute($this->createTimeField) && $this->getOwner()->getIsNewRecord() && !$this->getOwner()->{$this->createTimeField})
			$this->getOwner()->{$this->createTimeField} = $time;
			
		if($this->getOwner()->hasAttribute($this->updateTimeField) && !$this->getOwner()->{$this->updateTimeField})
			$this->getOwner()->{$this->updateTimeField} = $time;
	}

}

?>